<?php
namespace app\common\model\mysql;

use think\Model;
class User extends Model{
	// 指定数据库表
	public $table = 'mall_user';
	// 根据手机号码获取用户信息数据
	public function getUserByPhoneNumber($phoneNumber){
		if(empty($phoneNumber)){
			return false;
		}

		$where = [
			"phone_number" => trim($phoneNumber)
		];

		$result = $this->where($where)->find();
		return $result;
	}

	//根据主键ID更新用户信息
	public function updateUserByUserId($id,$data){
		$id = intval($id);
		if(empty($id) || empty($data) || !is_array($data)){
			return false;
		}

		$where = [
			"id" => $id,
		];

		return $this->where($where)->save($data);
	}

	// 根据主键ID获取用户信息
	public function getUserById($id){
		$id = intval($id);
		if(!$id){
			return false;
		}

		return $this->find($id);
	}

	// 根据用户名获取用户信息数据
	public function getUserByUserName($username){
		if(empty($username)){
			return false;
		}

		$where = [
			'username' => trim($username),
		];

		$result = $this->where($where)->find();
		return $result;
	}
}